package com.example.algorithm.quicksort;

import com.example.algorithm.util.ArrayGenerator;
import com.example.algorithm.util.SortingHelper;
import com.example.algrithm.quicksort.QuickSort;
import org.junit.Test;

import java.util.Arrays;

public class QuickSortTest {

    @Test
    public void test1() {
        Integer[] arr = new Integer[]{1, 9, 4, 65, 2, 4, 0, 23, 23, 21, 456};
        QuickSort.sort(arr);
        for (Integer item : arr) {
            System.out.print(item + ",");
        }
    }

    @Test
    public void test2() {
        int size = 50000;
        Integer[] orderedArray = ArrayGenerator.generateOrderedArray(size);
        Integer[] arr2 = Arrays.copyOf(orderedArray, orderedArray.length);
//        Integer[] randomArray = ArrayGenerator.generateRandomArray(size, size);
        SortingHelper.sortTest("QuickSort2", arr2);
        SortingHelper.sortTest("QuickSort1", orderedArray);
    }

    @Test
    public void testsort2ways() {
        int n = 100000;
        Integer[] arr = ArrayGenerator.generateRandomArray(n, n);
        Integer[] arr2 = Arrays.copyOf(arr, arr.length);
        SortingHelper.sortTest("QuickSort2ways", arr);
        SortingHelper.sortTest("QuickSort2", arr2);
    }

    @Test
    public void testsort2ways2() {
        int n = 100000;
        Integer[] arr = ArrayGenerator.generateRandomArray(n, 1);
        Integer[] arr2 = Arrays.copyOf(arr, arr.length);
        Integer[] arr3 = Arrays.copyOf(arr, arr.length);
        Integer[] arr4 = Arrays.copyOf(arr, arr.length);
        System.out.println("Random array:");
        SortingHelper.sortTest("QuickSort2", arr2);
        SortingHelper.sortTest("QuickSort2ways", arr);
        SortingHelper.sortTest("QuickSort2ways2", arr3);
        SortingHelper.sortTest("QuickSort3ways", arr4);
        System.out.println();

        arr = ArrayGenerator.generateOrderedArray(n);
        arr2 = Arrays.copyOf(arr, arr.length);
        arr3 = Arrays.copyOf(arr, arr.length);
        arr4 = Arrays.copyOf(arr, arr.length);
        System.out.println("Ordered array:");
        SortingHelper.sortTest("QuickSort2", arr2);
        SortingHelper.sortTest("QuickSort2ways", arr);
        SortingHelper.sortTest("QuickSort2ways2", arr3);
        SortingHelper.sortTest("QuickSort3ways", arr4);
        System.out.println();

        arr = ArrayGenerator.generateRandomArray(n, 1);
        arr2 = Arrays.copyOf(arr, arr.length);
        arr3 = Arrays.copyOf(arr, arr.length);
        arr4 = Arrays.copyOf(arr, arr.length);
        System.out.println("Same value array:");
        SortingHelper.sortTest("QuickSort2", arr2);
        SortingHelper.sortTest("QuickSort2ways", arr);
        SortingHelper.sortTest("QuickSort2ways2", arr3);
        SortingHelper.sortTest("QuickSort3ways", arr4);
    }
}
